;(function() {
		init_parsley();
		$("#read_card_query").click(function(){
		    loading();
		    var card_no=$("#card_no").val();
			$.post(
					"/admin/member/query",
					{"card_no":card_no},
					function(data){
						close_loading();
						if(data.flag){
							$("#name").val(data.data.name);
							$("#mobile").val(data.data.mobile);
							$("#headimage").val(data.data.headimage);
							if(data.data.headimage.length>5){
								$("#face_image1").attr("src",data.data.headimage);
							}
							toastr['success'](data.msg);
						}else{
							toastr['error'](data.msg);
						}
					}
				)
		});
	
		$(".btn_face_camare").click(function(){
			var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
				var step=$(this).attr("data-step");
				if(step=="1"){
					open_camare(0);
				}else if(step=="2"){
					var card_no=$("#card_no").val();
					if(card_no.length<6){
						toastr['error']("卡号不正确","操作失败！"); 
						return false;
					}
					var csharp=window.external;
					var faces= csharp.GetFaceCode(card_no);
					if(faces==null||faces.length<1000){
						toastr["error"]("模板不清晰，请重新拍摄");
						return false;
					}else{				
						faces=faces.split(",");
					    $("#face1").val(faces[0]);
					}
					var arr=csharp.GetFaceUrl().split(",");
					$("#face_image1").attr("src",arr[0]);
					$("#headimage").val(arr[0]);
					loading();
					$.get(
						"/Api/UploadFace/save_extral",
						{"card_no":$("#card_no").val(),"shop_id":$("#shop_id").val(),"headimage_url":$("#headimage").val(),"has_return":1},
						function(data){
							close_loading();
							toastr['success']("操作成功！", ''); 
						},
						"json"
						
					);
				}else{
					alert("无效的点击");
				}
			}
		   return false;											
		})
		
		$("#upload").click(function(){
			$("#uploadfile").trigger("click");
			return false;
		});
		
		$("#uploadfile").change(function(){
			var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
	   		 var formData = new FormData();
             formData.append("file", document.getElementById("uploadfile").files[0]);  
             formData.append("shop_id", $("#shop_id").val());  
             formData.append("card_no", $("#card_no").val());
              loading();
              $.ajax({
                    url: "/Api/UploadFace/upload_img",
                    type: "POST",
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                    	close_loading();
						if(data.flag){
							toastr["success"]("上传成功");
							$("#face_image1").attr("src",data.data);
							$("#headimage").val(data.data);
						}else{
							toastr["error"](data.msg);
						}
						return false;
                    },
                    error: function () {
                    	close_loading();
                        toastr["error"]("上传失败");
                    }
                });
	   		}
			return false;
		});
	   	$("#form-submit").click(function(){
	   		var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
	   			$.post(
	   				"/admin/member/varify",
	   				$("#validate-form").serialize(),
	   				function(data){
			      		if(data.flag){
			      			toastr['success']("操作成功！", ''); 
			      		}else{
			      		 	toastr['error'](data.msg,"操作失败！"); 
			      		}
	   				}
	   			);
	   		}
	   	})
})();